package org.hxyjs.controller;

import org.hxyjs.dto.DTO;
import org.hxyjs.entity.Festival;
import org.hxyjs.entity.Festival;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.FestivalService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@Controller
@RequestMapping("/festivalController")
public class FestivalController {
	@Resource
	FestivalService festivalService;
	@RequestMapping("/getAllFestival")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
    public DTO<Festival> getAllFestival() throws Exception {
    	System.out.println("查询全部节日");
		return festivalService.getAllFestivals();
    }

	@RequestMapping("/deleteFestivalByFno/{fno}")
	@ResponseBody
    public DTO<Festival> deleteFestivalByFno(@PathVariable("fno") String fno) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
    	System.out.println(fno+"删除节日");
    	return festivalService.deleteFestivalByFno(fno);
    }

	@RequestMapping("/updateFestivalByFno")
	@ResponseBody
	public DTO<Festival> updateFestivalByFno(@RequestBody Festival festival) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("修改节日");
		return festivalService.updateFestivalByFno(festival);
	}


	@RequestMapping("/addFestival")
	@ResponseBody
	public DTO<Festival> addFestival(@RequestBody Festival festival) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("增加节日");
		System.out.println(festival);
 		return festivalService.addFestival(festival);
	}
	@RequestMapping("/getFestivalByPage")
	@ResponseBody
	public DTO<Festival> getFestivalByPage(PageInfo pageInfo) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("分页管理员");
		return festivalService.getFestivalByPage(pageInfo);
	}

}